export function assert(exp, msg = 'assert faild') {
    if (!exp) {
        throw new Error(msg)
    }
}

//合并参数
export function mergeOptions(target, source) {


    for (let name in source) {

        if (typeof source[name] === 'object') {
            if (!target[name]) {
                target[name] = {}
            }

            mergeOptions(target[name], source[name]);

        } else {

            if (source[name] !== undefined) {
                target[name] = source[name];
            }

        }

    }

    return target;

}


export function clone(obj) {

    switch (typeof obj) {
        case 'object':
            let obj2;
            if (obj instanceof Array) {
                obj2 = [];
                for (let i = 0; i < obj.length; i++) {
                    obj2[i] = clone(obj[i]);
                }
            } else {
                obj2 = {};
                for (let key in obj) {
                    obj2[key] = clone(obj[key])
                }
            }

            return obj2;
        default:
            return obj;
    }
    //return JSON.parse(JSON.stringify(obj));
}